Coupling Between Test Methods ^^^^^ Definition:
- Test methods (and all tests in general) must be perfectly isolated from each other. This means that changing one test must not affect any others.
Code Example:
public final class MetricsTest {
private File temp;
private Folder folder;
@Before
public void prepare() {
this.temp = Files.createTempDirectory("test");
this.folder = new DiscFolder(this.temp);
this.folder.save("first.txt", "Hello, world!");
this.folder.save("second.txt", "Goodbye!");
}
@After
public void clean() {
FileUtils.deleteDirectory(this.temp);
}
@Test
public void calculatesTotalSize() {
assertEquals(22, new Metrics(this.folder).size());
}
@Test
public void countsWordsInFiles() {
assertEquals(4, new Metrics(this.folder).wc());
}
}
References:
Quality attributes
file-code;1em
- Code Examplecomment-discussion;1em
- Cause and Effectgraph;1em
- Frequencysync;1em
- Refactoring
- A few thoughts on unit test scaffolding
file-code;1em
comment-discussion;1em
sync;1em
- Refactoring Test Smells With JUnit 5: Why Should Developers Keep Up-to-Date?